/*
 * @Description:工具函数
 * @Version: 2.0
 * @Autor: kafei
 * @Date: 2021-11-30 18:07:20
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-01-24 11:54:58
 */
export const changeLabel = (data, value) => {
  const target = data.find((v) => `${v.value}` === `${value}`)
  let label = ''
  if (target) {
    label = target.label
  }
  return label
}

export const changeArrTolabel = (data, str) => {
  let arr = typeof str === 'string' ? str.split(',') : str
  let result = ''
  arr = arr.filter((v) => v.length > 0)
  if (arr && arr.length > 0) {
    for (let i = 0; i < arr.length; i++) {
      const value = arr[i]
      result += changeLabel(data, value) + ','
    }
    return result.substring(0, result.length - 1)
  }
}

/**
 * @description: 处理表单list变成rules
 * @param {list} 数据集合
 * @return {rules} {}
 * @author: kafei
 */
export const getListToRules = (list) => {
  if (!list || list.length === 0) {
    return {}
  }
  return list.reduce((cur, next) => {
    if (next.pattern && next.pattern.length > 0) {
      cur[next.props] = next.pattern
    }
    return cur
  }, {})
}
